---
title: "Svn笔记"
categories:
- linux
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org6c6a8ce">svn ignore 忽略文件</a></li>
<li><a href="#org66b55d8">svn 取消ADD</a></li>
</ul>
</div>
</div>
<div class="outline-2" id="outline-container-org6c6a8ce">
<h2 id="org6c6a8ce">svn ignore 忽略文件</h2>
<div class="outline-text-2" id="text-org6c6a8ce">
<blockquote>
<p>
<a href="https://stackoverflow.com/questions/86049/how-do-i-ignore-files-in-subversion">https://stackoverflow.com/questions/86049/how-do-i-ignore-files-in-subversion</a>
</p>
</blockquote>
<p>
如果我们说“忽略文件”，我们期望的是：它不出现在列表中，甚至不会是unversioned的状态。对于SVN来说，文件就像不存在一样。
</p>
<p>
我们有三种方式：
</p>
<ol class="org-ol">
<li>Runtime Configuration Area - global-ignores option:
<ul class="org-ul">
<li>这是仅客户端的配置，也就是说，你的忽略列表是不与其他用户共享的。</li>
<li>应用于你本机上所有检出的仓库</li>
<li>配置文件的位置在：
<ul class="org-ul">
<li>Windows (file-based) - C:\Users\{you}\AppData\Roaming\Subversion\config</li>
<li>Windows (registry-based) - Software\Tigris.org\Subversion\Config\Miscellany\global-ignores in both HKLM and HKCU.</li>
<li>Linux/Unix - ~/.subversion/config</li>
</ul></li>
</ul></li>
<li><p>
The svn:ignore property, which is set on directories (not files):
</p>
<ul class="org-ul">
<li>这个配置存储在仓库中，因此是与其他用户共享的。与.gitignore相似。</li>
<li>svn:ignore是应用于目录的，但是并不继承。只有目录下的文件和一级子目录会被忽略，也就是在目录下ls出来的那些文件被忽略（目录也是文件），面二级目录下的内容不会被忽略。</li>
</ul>
<div class="org-src-container">
<pre class="src src-sh"><span style="font-weight: bold;">cd</span> ~/myRepoRoot                             <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">cd 进入仓库</span>
<span style="font-weight: bold;">echo</span> <span style="font-style: italic;">"foo"</span> &gt; <span style="font-style: italic;">"ignoreThis.txt"</span>                <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">创建文件 ignoreThit.txt</span>

svn status                                  
&gt; ?    ./ignoreThis.txt
&gt; 1 unversioned file                        <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">这个文件的状态是 ?</span>

<span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">现在，我们开始设置忽略</span>

svn propset svn:ignore <span style="font-style: italic;">"ignoreThis.txt"</span> .   <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">不要忘记了命令最后的点号。这条命令表示设置当前目录的忽略列表</span>
svn status
&gt; 0 unversioned files                       <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">结果显示，该文件已被忽略</span>

<span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">现在，我们进入子目录，在子目录中创建同名文件</span>

<span style="font-weight: bold;">cd</span> subdirectory                             
<span style="font-weight: bold;">echo</span> <span style="font-style: italic;">"foo"</span> &gt; <span style="font-style: italic;">"ignoreThis.txt"</span>               

svn status
&gt; ?    ./subdirectory/ignoreThis.txt        <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">结果显示，子目录下的同名文件并没有被忽略</span>
&gt; 1 unversioned file
</pre>
</div>
<ul class="org-ul">
<li>由于svn 1.8中添加的“inherited properties”概念，在非一级子目录中，svn:ignore自身这个属性被忽略了。</li>
<li>要递归添加忽略，使用~svn propset svn:ignore &lt;filePattern&gt; . –recursive.~
<ul class="org-ul">
<li>这条命令是递归地在子目录中创建svn:ignore属性。</li>
<li>子目录中定义的svn:ignore覆盖上级中的定义</li>
</ul></li>
</ul></li>
<li><p>
The svn:global-ignores property. Requires SVN 1.8
</p>
<ul class="org-ul">
<li>svn 1.8中的功能，与svn:ignore相似，除了它会使用1.8中"inherited properties"的概念</li>
<li>应用于目录下所有文件，包含子目录</li>
</ul>
<div class="org-src-container">
<pre class="src src-sh"><span style="font-weight: bold;">cd</span> ~/myRepoRoot                                    <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">Open an existing repo</span>
<span style="font-weight: bold;">echo</span> <span style="font-style: italic;">"foo"</span> &gt; <span style="font-style: italic;">"ignoreThis.txt"</span>                       <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">Create a file called "ignoreThis.txt"</span>
svn status                                         <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">Check to see if the file is ignored or not</span>
&gt; ?    ./ignoreThis.txt
&gt; 1 unversioned file                               <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">...it is NOT currently ignored</span>

svn propset svn:global-ignores <span style="font-style: italic;">"ignoreThis.txt"</span> .
svn status
&gt; 0 unversioned files                              <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">...but now the file is ignored!</span>

<span style="font-weight: bold;">cd</span> subdirectory                                    <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">now open a subdirectory</span>
<span style="font-weight: bold;">echo</span> <span style="font-style: italic;">"foo"</span> &gt; <span style="font-style: italic;">"ignoreThis.txt"</span>                       <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">create another file named "ignoreThis.txt"</span>
svn status
&gt; 0 unversioned files                              <span style="font-weight: bold; font-style: italic;"># </span><span style="font-weight: bold; font-style: italic;">the file is ignored here too!</span>
</pre>
</div></li>
</ol>
<p>
我们通过–no-ignore开关显示忽略的文件：
</p>
<div class="org-src-container">
<pre class="src src-sh">svn status --no-ignore | grep <span style="font-style: italic;">"^I"</span>
</pre>
</div>
<p>
svn propset子命令相关的有propedit, proplist, propget等，通过这些命令我们能丁查看设置的属性
</p>
</div>
</div>
<div class="outline-2" id="outline-container-org66b55d8">
<h2 id="org66b55d8">svn 取消ADD</h2>
<div class="outline-text-2" id="text-org66b55d8">
<blockquote>
<p>
<a href="https://stackoverflow.com/questions/2906892/unadd-a-file-to-svn-before-commit">https://stackoverflow.com/questions/2906892/unadd-a-file-to-svn-before-commit</a>
</p>
</blockquote>
<p>
取消svn add的文件，但是仍然保留在文件系统中。使用这个命令之后，svn status会显示这些文件的状态为?
</p>
<div class="org-src-container">
<pre class="src src-sh">https://stackoverflow.com/questions/2906892/unadd-a-file-to-svn-before-commit
</pre>
</div>
<p>
svn revert是大部分网友给出的解决方案，但是使用这个命令一定慎重，svn reverst会丢弃文件的更改。
</p>
<div class="org-src-container">
<pre class="src src-sh">svn revert --recursive example_folder
</pre>
</div>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
